package com.access.boot.autoconfigure.apisdk.proxy;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Yangzhen
 * @date 2022/6/13 11:09
 * @since 1.0.0
 */
@Slf4j
public class MethodWrapperCache {

    private static final Map<Method, MethodWrapper> SOURCE_METHOD_METHOD_WRAPPER = new ConcurrentHashMap<>();

    public static void put(Method method, MethodWrapper methodWrapper) {
        SOURCE_METHOD_METHOD_WRAPPER.putIfAbsent(method, methodWrapper);
    }

    public static boolean isAutoType(Method method) {
        MethodWrapper methodWrapper = SOURCE_METHOD_METHOD_WRAPPER.get(method);
        if (methodWrapper != null) {
            return methodWrapper.isAutoType();
        }
        return false;
    }

    public static void print() {
        SOURCE_METHOD_METHOD_WRAPPER.forEach(
                (k, v) -> {
                    log.info("source method: {}, method wrapper: {}", k, v);
                }
        );
    }
}
